package soul.service;

import soul.entity.Meta;
import soul.mapper.MetaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2016/11/26.
 */
@Service
public class MetaService {

    @Autowired
    private MetaDao metaDao;

    public int addMeta(Meta meta) {
        Assert.notNull(meta);
        Assert.notNull(meta.getId());
        Assert.notNull(meta.getOrgId(),"缺少组织");
        return metaDao.add(meta);
    }

    public List<Meta> select(Map<String, Object> param) {
        Assert.notNull(param);
        List orgIds = (List) param.get("orgIds");
        List<Meta> metas = new ArrayList<>();
        for (Object orgId : orgIds) {
            param.put("orgId", orgId);
            metas.addAll(metaDao.select(param));
        }
        return metas;
    }

    public int confirm(Meta meta){
        Assert.notNull(meta,"meta == null");
        Assert.notNull(meta.getId(),"metaid == null");
        return metaDao.confirm(meta);
    }

    public int delete(Meta meta){
        Assert.notNull(meta,"meta == null");
        Assert.notNull(meta.getId(),"metaid == null");
        return metaDao.delete(meta);
    }
}
